package com.founder.gateway.system.util;

import org.apache.ibatis.scripting.xmltags.OgnlCache;

import java.math.BigDecimal;

public class ExpressionEvaluator {
    public boolean evaluateBoolean(String expression, Object parameterObject) {
        Object value = OgnlCache.getValue(expression, parameterObject);
        if (value instanceof Boolean) {
            return (Boolean) value;
        } else if (value instanceof Number) {
            return !(new BigDecimal(String.valueOf(value))).equals(BigDecimal.ZERO);
        } else {
            return value != null;
        }
    }

    public String evaluateString(String expression, Object parameterObject) {
        Object value = OgnlCache.getValue(expression, parameterObject);
        return value == null ? null : value.toString();
    }
}
